$(document).ready(function(){
		/*列表控件*/
	$('#sendemail_log_tt').datagrid({
		title: '邮件发送日志'
		, fit: true
		, url: 'sendemail-log.php?method=GetData'
		, pagination: true /*底部分页栏*/
		, pageList: [100, 200, 500]
		, loadMsg: '正在加载数据，请稍等 ...'
		, singleSelect: true
		, columns:[[
			{field:'id', title:'ID序号', width:60}
			, {field:'to', title:'群发对象', width:100}
			, {field:'subject', title:'标题', width:200}
			, {field:'#look', title:'查看内容', width:80, align: 'center', formatter:function(value, rowData){
				return "<a href='javascript:void(0)' onclick='LookEmailBody(" + rowData.id + ")'>查看详情</a>";
			}}
			, {field:'success', title:'状态', width:80, align:'center', formatter:function(value, rowData){
				if(0 == value)
					return "<font color=red>等待发送</font>";
				return "<font color=green>发送完成</font>";
			}} 
			, {field:'count_s', title:'发送成功数', width:80, align:'right'}
			, {field:'count_f', title:'发送失败数', width:80, align:'right', formatter:function(value, rowData){
				if(0 == value)
					return value;
				return "<font color=red><b>" + value + "</b></font>";
			}} 
			, {field:'first_dt', title:'开始发送时间', width:130, align:'center'}
			, {field:'last_dt', title:'发送完成时间', width:130, align:'center'} 
			, {field:'#opt', title:'操作', width:80, align:'center', formatter: function(value, rowData){
				return "<a href='javascript:void(0)' onclick='DeleteLog(" + rowData.id + ")'>删除</a>";
			}}
		]]
	});
	$('#sendemail_log_dd').window('close');
});

/*查看邮件内容*/
function LookEmailBody(id){
	$('#sendemail_log_dd').window({
		title: "查看id为" + id + "的邮件内容"
		, content: '<iframe width="100%" height="100%" scrolling="auto" frameborder="0" src="sendemail-log.php?method=LookBody&id=' + id + '"></iframe>'
	});
}

/*删除日志*/
function DeleteLog(id){
	top.$.messager.confirm('确认操作', '确实要删除id为' + id + '的邮件记录吗？', function(r){
		if(!r) return;
		/*AJAX提交确认操作*/
		$.ajax({type:'POST'
			, url: 'sendemail-log-action.php?type=delete'
			, data: 'id=' + id
			, dataType: 'json'
			, error: function(XMLHttpRequest, textStatus, errorThrown){
				top.$.messager.alert('错误', '请求失败:' + errorThrown, 'error');
			}
			,success: function(msg){
				if(msg.success){
					top.$.messager.alert('操作成功', '删除记录成功', 'info');
					$('#sendemail_log_tt').datagrid('load');
				} else {
					top.$.messager.alert('操作失败', '删除记录失败:'+msg.msg, 'error');
				}
			}
		});
	});
}
